/**
 * @作者:黎谢之
 * @创建时间：2021/7/7
 * @修改时间：2021/7/10
 */
package com.example.senior_bug.controller;

import com.example.senior_bug.EntityClass.*;
import com.example.senior_bug.Service.BusinessService;
import com.example.senior_bug.ToolClass.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
@RequestMapping("/Business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    //测试
    @RequestMapping("/getAll")
    public Result GetAll() {
        return businessService.GetAll();
    }

    //商家首页获取自己发布的商品列表
    @RequestMapping("/getSkuList")
    public Result GetSkuListByBusinessName(@RequestParam(required = true) String StoreName) {
        return businessService.GetBusinessSkusByStoreName(StoreName);
    }

    //商家发布商品
    @RequestMapping(value = "/addNewSKU", method = RequestMethod.POST, produces = "application/json")
    public Result GddNewSKU(@RequestBody SKU sku) {
        return businessService.AddNewSku(sku);
    }

    //商家修改商品
    @RequestMapping(value = "/modifySKU", method = RequestMethod.POST, produces = "application/json")
    public Result ModifySKU(@RequestBody SKU sku) {
        return businessService.ModifySku(sku);
    }

    //商家发布商品时上传图片
    @RequestMapping(value = "/PostImage", method = RequestMethod.POST, produces = "application/json")
    public Result PostImage(@RequestParam("image") MultipartFile file, @RequestParam int skuId, @RequestParam int flag) {
        return businessService.UploadNewSkuImage(file, skuId, flag);
    }

    //商家通过手机号登录
    @RequestMapping("/LoginByPhone")
    public Result LoginByPhone(@RequestParam String PhoneNum, @RequestParam String Password) {
        return businessService.LoginByPhoneNum(PhoneNum, Password);
    }

    //商家通过邮箱号登录
    @RequestMapping("/LoginByEmail")
    public Result LoginByEmail(@RequestParam String Email, @RequestParam String Password) {
        return businessService.LoginByEmail(Email, Password);
    }

    //商家修改个人信息
    @RequestMapping(value = "/ModifyTheInfo", method = RequestMethod.POST, produces = "application/json")
    public Result ModifyTheInfo(@RequestBody Business business) {
        return businessService.ModifyTheInfo(business);
    }

    //获取商家对象通过主键
    @RequestMapping("/getBusinessById")
    public Result GetCustomerById(@RequestParam int Id) {
        return businessService.getById(Id);
    }

    //商家带头像注册
    @RequestMapping(value = "/RegisterWithFaceImage", method = RequestMethod.POST, produces = "application/json")
    public Result RegisterWithFaceImage(@RequestParam("face") MultipartFile file, String identityNum,
                                        String name, String passWord, String phoneNum,
                                        String storeName, String email) {
        Business business = new Business();
        business.setIdentityNum(identityNum);
        business.setName(name);
        business.setStoreName(storeName);
        business.setPassWord(passWord);
        if (phoneNum != null)
            business.setPhoneNum(phoneNum);
        if (email != null)
            business.setEmail(email);
        return businessService.RegisterWithFaceImage(file, business);
    }

    //商家获取与其聊天的所有用户所需信息
    @RequestMapping("/getAllCustomer")
    public Result GetAllCustomer(@RequestParam int BusinessId) {
        return businessService.getAllCustomer(BusinessId);
    }

    //商家添加新的用户与其交流
    @RequestMapping("/AddNewCustomer")
    public Result CommunicateWithNewCustomer(int CustomerId, int BusinessId) {
        return businessService.CommunicateWithNewCustomer(BusinessId, CustomerId);
    }

    //商家下架商品
    @RequestMapping("/DownTheSKU")
    public Result DownTheSKU(@RequestParam int SKUId) {
        return businessService.DownTheSKU(SKUId);
    }
}
